#include <iostream>
#include <unordered_map>
#include <cmath>

bool isPrime(int n) {
    if (n < 2) {
        return false;
    }
    for (int i = 2; i <= sqrt(n); ++i) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int closestPrime(int n) {
    if (isPrime(n)) {
        return n;
    }
    int lower = n - 1;
    int upper = n + 1;
    while (true) {
        if (lower >= 2 && isPrime(lower)) {
            return lower;
        } else if (isPrime(upper)) {
            return upper;
        }
        --lower;
        ++upper;
    }
}

int main() {
    std::unordered_map<std::string, int> wordToNumber = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };

    std::string input1, input2, input3;
    std::cin >> input1 >> input2 >> input3;

    if (wordToNumber.find(input1) == wordToNumber.end() ||
        wordToNumber.find(input2) == wordToNumber.end() ||
        wordToNumber.find(input3) == wordToNumber.end()) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    int number = wordToNumber[input1] * 100 +
                 wordToNumber[input2] * 10 +
                 wordToNumber[input3];

    if (number >= 100 && number <= 999) {
        std::cout << closestPrime(number) << std::endl;
    } else {
        std::cout << "Wrong input" << std::endl;
    }

    return 0;
}
